import api from "@/api/api";
// import mixin from '../../mixin'
import popUp from '@/components/popUp'
import { getLocation } from '@/util/uniapi'
import { getParamsBydecodeURI } from '@/util/util'
import popSetLocation from '@/components/popSetLocation'
import popRecord from '@/components/popRecord'
import { compareTime } from "@/util/util";
export default {
  components: {
    popUp, popSetLocation, popRecord
  },
  // mixin: [mixin],
  data() {
    return {
      title: "hello",
      content: "复制的文案",
      location: {}
    };
  },


  async onReady() {
    this.initShareData();
  },
  async onLoad(option) {
    this.getConfig();
    if (option.code_ticket) {
      /**
       * 用后清除！！！
       */
      uni.setStorageSync('code_ticket', option.code_ticket);

    }
  },

  methods: {
    /**
     * 模板消息授权
     */
    sendMsg() {
      /**
       * tmplIds 模板消息id
       */
      uni.requestSubscribeMessage({
        tmplIds: [''],
        success(res) { }
      })
    },
    /*
    *H5订阅通知
    */
    sendH5Message(){

    },
    openRecord() {
      this.$refs.popRecord.popReord = true
    },
    jump(url) {
      uni.navigateTo({ url: url })
    },
    jumpWeb(url) {
      uni.navigateTo({ url: `${url}?src=${encodeURIComponent('http://jsondemo.buffoon.cn/webviewMessage.html')}` })
    },
    async getlocation() {
      let res = await getLocation();
      console.log(res)
      if (res) {
        this.location = res;
      } else {
        this.location = null;
      }
    },
    openPopUp() {
      this.$refs.popUp.showPopUp = true
    },
    getCodeTicket() {

    },
    //拨打电话
    callPhone() {
      // #ifdef H5|| MP-WEIXIN
      uni.makePhoneCall({
        phoneNumber: "400-400-4000", //仅为示例
      });
      // #endif


    },
    //点击复制
    doCopy() {
      // #ifdef  MP-WEIXIN
      uni.setClipboardData({
        data: this.content,
        success: function () {
          console.log("success");
        },
      });
      // #endif

      // #ifdef  H5
      this.$copyText(this.content).then(function (e) {
        alert("H5复制成功");
        console.log(e);
      });
      // #endif
    },

    /**
     * 初始化微信分享参数
     */
    async initShareData() {
      if (this.$wechat && this.$wechat.isWechat()) {
        // 微信h5api
        this.$wechat.share({
          title: '分享标题',
          desc: "这里是分享",
          imgUrl: "http://img.sscai.club/click.jpeg",
          link: 'https://20kfcmaydemo.escase.cn/#/pages/prize/index',
        });
        let res = await this.$wechat.getLocation();
        if (res) {
          console.log(res)
          uni.showToast({
            title: "定位成功，详见打印！",
            icon: "none",
          });
        } else {
          uni.showToast({
            title: "定位失败",
            icon: "none",
          });
          this.location = 1
        }

      } else {
        // 小程序
        // #ifdef  MP-WEIXIN
        this.getlocation();
        // #endif
      }
    },
    getPrize() {
      // #ifdef H5
      uni.navigateTo({
        url: "../prize/index",
      });
      // #endif
    },

    /**
     * 获取手机号码
     */
    async decryptPhoneNumber(e) {
      if (e.detail.encryptedData) {
        let params = {
          encryptedData: e.detail.encryptedData, //加密数据 ,
          iv: e.detail.iv, //加密算法的初始向量
        };

        uni.navigateTo({
          url: "../prize/index",
        });
      } else {
        uni.showToast({
          icon: "none",
          title: "请授权手机号码！",
        });
      }
    },
    /**
     * 前端配置
     */
    async getConfig() {
      let res = await this.$post(api.GetWebConfig, { ConfigType: 30 });
      if (res.Success) {
      }
    },
  },
  onShareAppMessage: function (res) {
    return {
      title: '自定义分享标题'
    }
  },

};